<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Alpine.js x-init directive.</title>

    <script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>
</head>
<body>

<div x-init="console.log('Init')"></div>

<div x-data="{todo: {}}" x-init="todo = await (await fetch('https://jsonplaceholder.typicode.com/todos/10')).json();">
    <span x-text="`Todo ID: ${todo.id}`"></span>
</div>

<div x-data="{
    init() {
        console.log('I am initialized')
    }
}">
</div>

<div x-data>
    <span x-init="console.log('Init too')"></span>
</div>

</body>
</html>